home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr47 / wasm223.zip / SHELL1.ASM < prev    next >
Assembly Source File  |  1993-05-04  |  4KB  |  148 lines

  1. ;********************************;
  2. ; WASM System Shell, Run Program ;
  3. ; By Eric Tauck                  ;
  4. ;                                ;
  5. ; Defines:                       ;
  6. ;                                ;
  7. ;   RunPro  execute a program    ;
  8. ;                                ;
  9. ; Requires:                      ;
  10. ;                                ;
  11. ;   STACK.ASM                    ;
  12. ;   STRING.ASM                   ;
  13. ;********************************;
  14.  
  15.         jmp     _shell1_end
  16.  
  17. _SHELL_MAXINP   EQU     128     ;maximum input length
  18. _shell_FCB_size EQU     37      ;size of FCB
  19.  
  20. ;--- offsets of shell parameter block
  21.  
  22. _shell_enviro   EQU     0       ;environment
  23. _shell_cmdlin   EQU     2       ;command line offset
  24. _shell_fcb1     EQU     6       ;first FCB offset
  25. _shell_fcb2     EQU     10      ;second FCB offset
  26. _shell_size     EQU     14      ;size of shell parameter block
  27.  
  28. ;--- saved stack
  29.  
  30. _shell_ss       DW      ?       ;saved SS
  31. _shell_sp       DW      ?       ;saved SP
  32.  
  33. ;========================================
  34. ; Execute a program.
  35. ;
  36. ; In: AX= address of command; BX= address
  37. ;     of command line.
  38. ;
  39. ; Out: CY= set if error; AL= DOS error
  40. ;      code.
  41.  
  42. RunPro  PROC    NEAR
  43.         push    di
  44.         push    si
  45.         push    bp
  46.         push    ds
  47.         push    es
  48.  
  49.         mov     di, ax          ;save program name
  50.         mov     bp, bx          ;save command line address
  51.  
  52. ;--- allocate memory
  53.  
  54.         StkAll  si, _shell_size                 ;allocate parameter block
  55.         mov     ax, [002CH]                     ;this program's environment
  56.         mov     [si + _shell_enviro], ax
  57.         StkAll  ax, _SHELL_MAXINP + 2           ;allocate input space
  58.         mov     [si + _shell_cmdlin], ax
  59.         StkAll  ax, _shell_FCB_size             ;allocate first FCB
  60.         mov     [si + _shell_fcb1], ax
  61.         StkAll  ax, _shell_FCB_size             ;allocate second FCB
  62.         mov     [si + _shell_fcb2], ax
  63.         mov     ax, ds                          ;save segments
  64.         mov     [si + _shell_cmdlin + 2], ax
  65.         mov     [si + _shell_fcb1 + 2], ax
  66.         mov     [si + _shell_fcb2 + 2], ax
  67.  
  68. ;--- set up command line
  69.  
  70.         push    di
  71.         push    si
  72.  
  73.         mov     ax, bp
  74.         call    StrLen                  ;get length of input
  75.         cmp     ax, _SHELL_MAXINP       ;check if too large
  76.         jbe     _rnpro1
  77.         mov     ax, _SHELL_MAXINP
  78.  
  79. _rnpro1 push    WORD [si+_shell_fcb2]   ;
  80.         push    WORD [si+_shell_fcb1]   ;save FCB locations for later
  81.  
  82.         cld
  83.         mov     di, [si+_shell_cmdlin]  ;place to store command line
  84.         push    di                      ;save for parsing
  85.         stosb                           ;store length
  86.         mov     cx, ax
  87.         mov     si, bp
  88.         rep
  89.         movsb                   ;copy rest of string
  90.         mov     al, 13          ;carriage return
  91.         stosb                   ;store it
  92.  
  93. ;--- set up FCB's
  94.  
  95.         pop     si
  96.         inc     si              ;skip length
  97.         pop     di
  98.         mov     ax, 2901H       ;parse file name function
  99.         int     21H             ;execute
  100.  
  101.         pop     di
  102.         mov     ax, 2901H       ;parse file name function
  103.         int     21H             ;execute
  104.  
  105.         pop     si
  106.         pop     di
  107.  
  108. ;--- save stack pointers
  109.  
  110.         mov     _shell_ss, ss   ;save SS
  111.         mov     _shell_sp, sp   ;save SP
  112.  
  113. ;--- execute shell
  114.  
  115.         mov     ax, 4B00H       ;execute function
  116.         mov     dx, di          ;name of program
  117.         mov     bx, si          ;shell paramters
  118.         int     21H             ;execute
  119.  
  120.         mov     dx, ax          ;save return code
  121.         lahf                    ;save return flags
  122.  
  123. ;--- restore stack
  124.  
  125.         cli
  126.         seg     cs
  127.         mov     ss, _shell_ss   ;restore SS
  128.         seg     cs
  129.         mov     sp, _shell_sp   ;restore SP
  130.         sti
  131.  
  132.         StkRel  _shell_size, _SHELL_MAXINP + 2, _shell_FCB_size * 2
  133.  
  134. ;--- restore registers
  135.  
  136.         pop     es
  137.         pop     ds
  138.         pop     bp
  139.         pop     si
  140.         pop     di
  141.  
  142.         sahf                    ;restore flags
  143.         mov     ax, dx          ;restore return code
  144.         ret
  145.         ENDP
  146.  
  147. _shell1_end
  148.